﻿namespace Sidvall.Office
{
    public class Worksheet : Sidvall.Office.IWorksheet
    {
        #region Public Members

        #region DisplayOptions

        private WorksheetDisplayOptions _DisplayOptions;
        public WorksheetDisplayOptions DisplayOptions
        {
            get
            {

                if (_DisplayOptions == null)
                    _DisplayOptions = new WorksheetDisplayOptions(this);
                return _DisplayOptions;
            }
        }

        #endregion
        #region Name

        public string Name
        {
            get
            {
                return this.InternalWorksheet.Name;
            }
            set
            {
                this.InternalWorksheet.Name = value;
            }
        }

        #endregion
        #region Shapes

        private WorksheetShapeCollection _Shapes;
        public WorksheetShapeCollection Shapes
        {
            get
            {
                if (_Shapes == null)
                    _Shapes = new WorksheetShapeCollection(this);
                return _Shapes;
            }
        }

        #endregion

        #region GetText

        public string GetText(int rowIndex, int columnIndex)
        {
            return this.InternalWorksheet.Rows[rowIndex].Cells[columnIndex].GetText();
        }
        public string GetText(int rowIndex, int columnIndex, TextFormatMode textFormatMode)
        {
            return this.InternalWorksheet.Rows[rowIndex].Cells[columnIndex].GetText(Excel.GetTextFormatMode(textFormatMode));
        }

        #endregion
        #region GetValue

        public object GetValue(int rowIndex, int columnIndex)
        {
            return this.InternalWorksheet.Rows[rowIndex].Cells[columnIndex].Value;
        }

        #endregion
        #region GetWorksheetCell

        public IWorksheetCell GetWorksheetCell(int rowIndex, int columnIndex)
        {
            return new WorksheetCell(this.InternalWorksheet.Rows[rowIndex].Cells[columnIndex]);
        }

        #endregion
        #region GetWorksheetColumn

        public IWorksheetColumn GetWorksheetColumn(int columnIndex)
        {
            return new WorksheetColumn(this.InternalWorksheet.Columns[columnIndex]);
        }

        #endregion
        #region GetWorksheetRow

        public IWorksheetRow GetWorksheetRow(int rowIndex)
        {
            return new WorksheetRow(this.InternalWorksheet.Rows[rowIndex]);
        }

        #endregion
        #region MoveToIndex

        public void MoveToIndex(int index)
        {
            this.InternalWorksheet.MoveToIndex(index);
        }

        #endregion
        #region SetValue

        public void SetValue(int rowIndex, int columnIndex, object value)
        {
            this.InternalWorksheet.Rows[rowIndex].Cells[columnIndex].Value = value;
        }

        #endregion
        #region ToString

        public override string ToString()
        {
            return "Worksheet - Sidvall.Office.IG";
        }

        #endregion

        #region IWorksheet Members

        IWorksheetDisplayOptions IWorksheet.DisplayOptions
        {
            get
            {
                return this.DisplayOptions;
            }
        }
        IWorksheetShapeCollection IWorksheet.Shapes
        {
            get
            {
                return this.Shapes;
            }
        }

        #endregion

        #endregion
        #region Private Members

        internal Infragistics.Documents.Excel.Worksheet InternalWorksheet { get; set; }

        #endregion
        #region Constructors

        public Worksheet(Infragistics.Documents.Excel.Worksheet worksheet)
        {
            this.InternalWorksheet = worksheet;
        }

        #endregion
    }
}
